package com.lantosec.hmrp.modules.eval.controller;


import com.lantosec.hmrp.core.log.ControllerLog;
import com.lantosec.hmrp.core.log.LogType;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.lantosec.hmrp.core.kit.Result;
import com.lantosec.hmrp.modules.eval.entity.EvalDetailedItem;
import com.lantosec.hmrp.modules.eval.service.IEvalDetailedItemService;
import com.lantosec.hmrp.modules.eval.vo.EvalDetailedItemVO;

import java.util.Arrays;
import java.util.List;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.RestController;
import com.lantosec.hmrp.core.mvc.BaseController;

/**
 *
 * 考评明细的项目 控制器
 *
 * @author AutoCode
 * @since 2020-03-30
 */
@Api(value = "考评明细的项目控制器", tags = "考评明细的项目控制器")
@RestController
@RequestMapping("/eval/detailed/item")
@Log4j2
public class EvalDetailedItemController extends BaseController {
    @Autowired
    private IEvalDetailedItemService service;

    @PostMapping("create")
    @ControllerLog(name = "新增追加考评项", type = LogType.add)
    @ApiOperation(value = "追加考评项")
    public Result<Integer> create(@ApiParam(value = "考评明细的项目VO对象", required = true) @RequestBody List<EvalDetailedItemVO> evalDetailedItemVOList){
        service.saveEvalDetailedItem(evalDetailedItemVOList);
        return Result.ok();
    }

    @PutMapping("updateDetailedItem/{evalDetailedItemId}")
    @ControllerLog(name = "修改考评项目值", type = LogType.update)
    @ApiOperation(value = "修改考评项目值")
    public Result<Void> updateDetailedItem(@ApiParam(value = "考评明细的项目ID", required = true) @PathVariable Integer evalDetailedItemId){
        service.updateDetailedItem(evalDetailedItemId);
        return Result.ok();
    }

    @PutMapping("update")
    @ControllerLog(name = "修改追加考评项", type = LogType.update)
    @ApiOperation(value = "修改数据")
    public Result<Void> update(@ApiParam(value = "考评明细的项目VO对象", required = true) @RequestBody EvalDetailedItemVO vo){
        EvalDetailedItem entity = vo.convertToEntity();
        service.updateById(entity);
        return Result.ok();
    }

    @DeleteMapping(value = "delete")
    @ControllerLog(name = "删除追加考评项", type = LogType.delete)
    @ApiOperation("删除追加项")
    public Result<Void> delete(@ApiParam(value = "考评记录项目明细ID", required = true) @RequestParam(name="evalDetailedItemId") Integer evalDetailedItemId,
                               @ApiParam(value = "追加项目ID", required = true) @RequestParam(name="evalItemId") String evalItemId){
        service.deleteEvalDetailItem(evalDetailedItemId,evalItemId);
        return Result.ok();
    }
}
